package netWorkPrograming.test.test03;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.SocketException;
import java.util.concurrent.CountDownLatch;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/5/28
 */
public class ReadThread implements Runnable{

    private Socket socket;
    private CountDownLatch countDownLatch;

    public ReadThread(Socket socket , CountDownLatch countDownLatch) {
        this.socket = socket;
        this.countDownLatch = countDownLatch;
    }

    @Override
    public void run() {
        try (
                BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        ){
            String str = null;
            while ((str = br.readLine())!=null){
                System.out.println("说："+str) ;
            }
        } catch (SocketException e) {
            System.out.println("下线了");
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            countDownLatch.countDown();
        }
    }
}
